<div class="row animate fadeIn">
    <form id="add_company_form" class="form-horizontal"  method="post">
        <div class="ibox-title" style="border:none;"><h5 style="color: #00afef"><i>Add Company</i></h5>
            <div class="ibox-tools">    
                <button  id="sads" class="btn btn-sm btn-primary save-btn-tab">Save</button>
                <a id = "cancel_add" class="btn btn-sm btn-outline btn-info cancel-btn-tab">Cancel</a>
            </div>
        </div>
        <div class="ibox-content">
          <div class="form-group"> 
              <label class="col-lg-4 control-label">Business Unit</label>
            <div class="col-lg-5">
              <select  id="" class="form-control chosen-select" name="bu_id">
                <?php foreach ($bu_data as $bu) { ?>
                  <option value="<?php echo $bu->bu_id; ?>"><?php echo $bu->bu_name; ?></option>
                <?php } ?>
              </select>
            </div>
          </div>   
          <div class="form-group"> 
              <label class="col-lg-4 control-label">Company Name</label>
            <div class="col-lg-5">
              <input type="text" name="comp_name" class="form-control">
            </div>
          </div>
          <div class="form-group"> 
              <label class="col-lg-4 control-label">Address 1</label>
            <div class="col-lg-5">
              <input type="text" name="comp_addr_1" class="form-control">
            </div>
          </div>
          <div class="form-group"> 
              <label class="col-lg-4 control-label">Address 2</label>
            <div class="col-lg-5">
              <input type="text" name="comp_addr_2" class="form-control">
            </div>
          </div>
          <div class="form-group"> 
              <label class="col-lg-4 control-label">Address 3</label>
            <div class="col-lg-5">
              <input type="text" name="comp_addr_3" class="form-control">
            </div>
          </div>
          <div class="form-group"> 
              <label class="col-lg-4 control-label">Cell/Telephone Number:</label>
            <div class="col-lg-5">
              <input type="text" name="comp_tel_num" class="form-control">
            </div>
          </div>
          <div class="form-group"> 
              <label class="col-lg-4 control-label">Tax Number</label>
            <div class="col-lg-5">
              <input type="text" name="comp_tax_num" class="form-control">
            </div>
          </div>
          <div class="form-group"> 
              <label class="col-lg-4 control-label">Logo File Name</label>
            <div class="col-lg-5">
              <input type="text" name="comp_logo_file" class="form-control">
            </div>
          </div>
          <div class="form-group">
              <label class="col-lg-4 control-label">Enable</label>
            <div class="col-lg-5">
              <input type="checkbox" value="ok" name="comp_ena" id="" class="i-checks" checked>
            </div>
          </div>
        </div>
    </form>
<!--  -->
</div>
<script>
  $(document).ready(function(){
    $('#add_company_form').data('serialize',$('#add_company_form').serialize());
    $(".chosen-select").chosen({width:"100%;"});
    $('.i-checks').iCheck({
      checkboxClass: 'icheckbox_square-green',
      radioClass: 'iradio_square-green',
    });

    $('#add_company_form').validate({
      rules :{
        comp_name :{
          required: true
        },
        comp_addr_1:{
          required: true
        },
        comp_tel_num:{
          required: true,
          number: true
        },
        comp_tax_num:{
          required: true
        },
        comp_logo_file:{
          required: true
        }
      },submitHandler: function(form){
          $.ajax({
              type: "POST",
              url: "<?php echo base_url($this->session->userdata('forajax').'/insert_company'); ?>",
              data: $('#add_company_form').serialize(),
              dataType: 'json',
            success: function(data){
              if(data[0].error == 1){
                  notifymsg("danger",data[0].msg);
              }else{
                  notifymsg("success",". . .New Company Added Successfully");
                  close_add(); active_search();
              }
            }      
          }); 
        }
    });

    function alert_cancel(){
            if($('#add_company_form').serialize()!=$('#add_company_form').data('serialize')){
                swal({
                    title: "Are you sure?",
                    text: "Your work will not be save",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "Leave",
                    cancelButtonText: "Stay",
                    closeOnConfirm: true,
                    closeOnCancel: true },
                function (isConfirm) {
                    if (isConfirm) {
                        close_add(); active_search();
                        notifymsg("hide","hide");
                    } else {
                        swal("Cancelled");
                    }
                });
                }else{
                close_add(); active_search();
                notifymsg("hide","hide");
            }
    } 
    $('#cancel_add').click(function () { 
      alert_cancel();
    });
    $('#addX').click(function(){
      alert_cancel();        
    });

  });
</script>